<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>文字滚动效果</title>
</head>
<body>
    <div id="str1">欢迎Beam学习JavaScript!&nbsp&nbsp&nbsp&nbsp</div>
    <script>
        function f1(){
            var tag = document.getElementById('str1');   //获取标签的id='str1'的行
            var content = tag.innerText;    //获取标签里面的字符串
            var first_char = content.charAt(0);   //获取字符串里的第一个元素
            var last_char = content.substring(1,content.length);    //获取指定下标的字符串
            var new_content = last_char + first_char;     //组成新的字符串
            tag.innerText = new_content;   //把新组成的字符串赋值到原来的字符串
            console.log(1);   //console.log()会在游览器的console里面输出，相同的字符串会累计，与这个效果无关
        }
        setInterval("f1();",500);   //定时器，每2秒执行一次f1方法
    </script>
</body>
</html>